package main

import (
	"fmt"
	"time"
)

func main() {
	ch := make(chan string)
	go func() {
		fmt.Println("zhangsan")
		ch <- "goroutine 完成"
	}()

	fmt.Println("我是main goroutine")

	v := <-ch
	fmt.Println("接收到chan中的值:", v)
	cacheCh := make(chan int, 5)
	cacheCh <- 2
	cacheCh <- 3
	fmt.Println("cacheCh 容量为:", cap(cacheCh), "元素个数为：", len(cacheCh))
	go func() {
		fmt.Println(<-cacheCh)
	}()
	close(cacheCh)

	//onlySend := make(chan<- int)
	//onlyResive := make(<-chan int)
	//onlySend <- 1
	//<-onlyResive

	firstCh := make(chan string)
	secondCh := make(chan string)
	threeCh := make(chan string)

	go func() {
		firstCh <- downLoad("first")
	}()
	go func() {
		secondCh <- downLoad("second")
	}()
	go func() {
		threeCh <- downLoad("three")
	}()
	select {
	case v := <-firstCh:
		fmt.Println("firstCh:", v)
	case v := <-secondCh:
		fmt.Println("second", v)
	case v := <-threeCh:
		fmt.Println("threeCh:", v)
	}

}

func downLoad(chanName string) string {
	time.Sleep(time.Second)
	return chanName + ":filePath"
}
